package com.lantu.sys.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.lantu.common.vo.RResult;
import com.lantu.sys.entity.Clazz;
import com.lantu.sys.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/clazz")
@CrossOrigin
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    @GetMapping("/allStudent/{pageNo}/{pageSize}")
    public RResult getAllClazz(@PathVariable("pageNo") Integer pageNo,
                               @PathVariable("pageSize") Integer pageSize,
                               Clazz clazz){
        Page<Clazz> pageParam = new Page<>(pageNo,pageSize);
        IPage<Clazz> clazzPage = clazzService.getClazzByOpr(pageParam,clazz);

        return RResult.ok(clazzPage);
    }

    //编辑和新增操作
    @PostMapping("/addOrUpdateStudent")
    public RResult addOrUpdateStudent(@RequestBody Clazz clazz){
        clazzService.saveOrUpdate(clazz);
        return RResult.ok();
    }

    //进行回显
    @GetMapping("/{id}")
    public RResult<Clazz> getUid(@PathVariable("id") Integer id){
        QueryWrapper<Clazz> clazzQueryWrapper = new QueryWrapper<>();
        clazzQueryWrapper.eq("id",id);
        Clazz one = clazzService.getOne(clazzQueryWrapper);
        return RResult.ok(one);
    }
    //通过id进行删除操作
    @DeleteMapping("/id/{id}")
    public RResult delClazzById(@PathVariable Integer id
    ){
        clazzService.removeById(id);
        return RResult.ok();
    }


}
